package com.meshnetics.gb.stack.mac.primitives;

import com.meshnetics.gb.stack.core.event.StackEventType;
import com.meshnetics.gb.stack.core.event.StackRequest;
import com.meshnetics.gb.stack.mac.RadioMACStackLayer;
import com.meshnetics.gb.type.impl.zcl.Bool;
import com.meshnetics.gb.type.impl.zcl.TypeBool;

import java.nio.ByteBuffer;

/**
 * WRITE DESCRIPTION HERE
 *
 * @author AKovylin
 */
public class MACResetRequest extends StackRequest implements MACCommand, MACReplyAwaited {
    public static final byte CODE = 0x54;

    private final Bool setDefaultPIB;

    public MACResetRequest(boolean setDefaultPIB) {
        this(Boolean.valueOf(setDefaultPIB));
    }

    public MACResetRequest(Boolean setDefaultPIB) {
        this((Bool) TypeBool.BOOLEAN.fromObject(setDefaultPIB));
    }

    public MACResetRequest(Bool setDefaultPIB) {
        super("macResetRequest", StackEventType.LME_TYPE);
        if (setDefaultPIB == null) {
            throw new NullPointerException("setDefaultPIB is null");
        }
        if (setDefaultPIB.isInvalid()) {
            throw new IllegalArgumentException("invalid setDefaultPIB");
        }
        this.setDefaultPIB = setDefaultPIB;
    }

    public Boolean isSetDefaultPIB() {
        return (Boolean) setDefaultPIB.toObject();
    }

    public Bool isSetDefaultPIBType() {
        return setDefaultPIB;
    }

    public int getSize(RadioMACStackLayer layer) {
        return 1;
    }

    public byte getCode() {
        return CODE;
    }

    public void serialize(ByteBuffer bb, RadioMACStackLayer layer) {
        setDefaultPIB.serialize(bb);
    }

    public String toString() {
        return getName() + '(' + setDefaultPIB + ')';
    }
}
